from sqlalchemy import String, Integer, BigInteger
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy import ForeignKey
from app.db.base import Base


class Rule(Base):
    __tablename__ = "rules"

    id: Mapped[str] = mapped_column(String(36), primary_key=True, index=True)
    account_id: Mapped[str] = mapped_column(String(36), ForeignKey("accounts.id"), nullable=False)
    ccode: Mapped[str] = mapped_column(String(20), nullable=False)
    ass: Mapped[str] = mapped_column(String(1), nullable=False)  # C=客户, V=供应商, P=个人
    name: Mapped[str] = mapped_column(String(100), nullable=False)
    classification: Mapped[str] = mapped_column(String(100), nullable=False)
    direction: Mapped[str] = mapped_column(String(2), nullable=False)  # 借/贷
    status: Mapped[int] = mapped_column(Integer, default=1, nullable=False)
    create_time: Mapped[int] = mapped_column(BigInteger, nullable=False)
    update_time: Mapped[int] = mapped_column(BigInteger, nullable=False)
    create_user_id: Mapped[str] = mapped_column(String(36), nullable=False)
    update_user_id: Mapped[str] = mapped_column(String(36), nullable=False)
    
    # 关联关系
    # account = relationship("Account", back_populates="rules")